{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "x_data = [ 338., 333., 328., 207., 226., 25., 179., 60., 208., 606.]\n",
    "y_data = [ 640., 663., 619., 393., 428., 27., 193., 66., 226., 1591.]\n",
    "\n",
    "n = 1\n",
    "X = np.ones((len(x_data),n + 1), dtype= np.float)\n",
    "Y = np.zeros((len(y_data)), dtype= np.float)\n",
    "\n",
    "\n",
    "row = 0\n",
    "for x in X:\n",
    "    x[0] = x_data[row]\n",
    "    #print(x)\n",
    "    row += 1\n",
    "#print(X)\n",
    "\n",
    "for i in range(0, len(y_data)):\n",
    "    Y[i] = y_data[i]\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "#求解析解\n",
    "Xt = np.transpose(X)\n",
    "X2 = np.matrix( np.matmul(Xt, X))\n",
    "XtXinv = X2.I\n",
    "XtXinvXt = np.matmul(XtXinv,Xt)\n",
    "W = np.matmul(XtXinvXt,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "#测试W0\n",
    "W = np.zeros((1, 2), dtype = np.float)\n",
    "W[0, 0] = 2.67\n",
    "W[0, 1] = --188.17"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "#测试W1\n",
    "W = np.zeros((1, 2), dtype = np.float)\n",
    "W[0, 0] = 2.67\n",
    "W[0, 1] = --188.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[   2.67956187 -187.97002933]]\n",
      "640.0 : 717.7218826777537 L: 77.72188267775368\n",
      "663.0 : 704.3240733284576 L: 41.324073328457644\n",
      "619.0 : 690.9262639791614 L: 71.92626397916138\n",
      "393.0 : 366.699277726193 L: -26.300722273807025\n",
      "428.0 : 417.61095325351863 L: -10.38904674648137\n",
      "27.0 : -120.98098258818902 L: -147.98098258818902\n",
      "193.0 : 291.67154537013425 L: 98.67154537013425\n",
      "66.0 : -27.19631714311555 L: -93.19631714311555\n",
      "226.0 : 369.3788395960523 L: 143.37883959605227\n",
      "1591.0 : 1435.8444638000306 L: -155.15553619996945\n",
      "L:9867.214847780182\n"
     ]
    }
   ],
   "source": [
    "#判断的出结果的好坏\n",
    "print(W)\n",
    "Yhead = np.matmul(W, np.transpose(X))\n",
    "L = Yhead - Y\n",
    "sum = 0\n",
    "row = 0\n",
    "for i in range(0,L.shape[1]):\n",
    "    print(str(Y[i]) + \" : \"+ str(Yhead[0, i]) + \" L: \" + str(L[0,i]))\n",
    "    sum += L[0,i]*L[0,i] \n",
    "    row += 1\n",
    "print(\"L:\" + str(sum/L.shape[1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZkAAAEQCAYAAABiGgneAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xl8VPW9//HXJyFB9kUWWYIBBSygrAURbVNX9LYuXW6hKmi1aKtttZtSe+vSa7V1q/7aarFylda1FZRaKiKKa0QBAUEIBIgkgICA7JCQfH5/zEkcMIRAZuacSd7Px2MeM+c758y8Yya+OcucY+6OiIhIMmSEHUBEROovlYyIiCSNSkZERJJGJSMiIkmjkhERkaRRyYiISNKktGTMLMfMXjWzJWa22Mx+HIy3NbMZZrY8uG8TjJuZPWBmhWa20MwGxb3W2GD+5WY2NpU/h4iI1I6l8nsyZtY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xs0buvg/AzLoCVwP3uHtpqOlEEkRHl4mkmJnlAquC29vA/xG7hvotwBrgdJWM1BfaXCaSepU7/b8KNAH+BdwJTAbOUcFIfaI1GRERSRqtyYiISNKoZEREJGlUMiIikjQqGRERSRqVjIiIJI1KRkREkkYlIyIiSaOSERGRpPn/4fHHh/wDNa4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画数据分布图\n",
    "Yhead = np.matmul(W, np.transpose(X))\n",
    "print(type(Yhead[0].tolist()))\n",
    "print()\n",
    "import matplotlib.pyplot as plt  # plt\n",
    "x = np.arange(0, 800, 8) # x\n",
    "y = np.arange(0, 2000,20) # y\n",
    "#x = np.arange(100, 200, 1) # bias\n",
    "#y = np.arange(-5, 5, 0.1) # weight\n",
    "Z = np.zeros((len(x), len(y)))\n",
    "# plot the figure\n",
    "plt.contourf(x, y, Z, 50, alpha=0.5, cmap=plt.get_cmap('jet'))\n",
    "# 李宏毅课程原代码为markeredeweight=3,无法运行，改为了marker=3。\n",
    "# ms和marker分别代表指定点的长度和宽度。\n",
    "plt.plot(x_data, y_data, 'o', ms=3, lw=1.5, color='black')\n",
    "plt.plot(x_data, Yhead.tolist()[0], 'o-', ms=3, lw=1.5, color='green')\n",
    "\n",
    "plt.xlim(0, 800)\n",
    "plt.ylim(0, 2000)\n",
    "plt.xlabel(r'$b$', fontsize=16)\n",
    "plt.ylabel(r'$w$', fontsize=16)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
